
//@flow
const {log} = console

function sum(n:number, m:number){
    return n+m
}

sum(100,'100')

function square(n):number{
    return  n*n
}

square('100')
//---------------------
// string number boolean 
const a:string = '234'

const b:number = Infinity // NaN

const c:boolean = true

const d:null = null
const e:void = undefined
const f:symbol = Symbol()
//-------------

const arr: Array<number> = ['444'] //
const arr1: number[] = []
const foo:[string, number] = ["rt",2] //元祖

//--------------- 对象字面量语法

const obj: {foo:string, bar: number} = {
    foo:"234",
    bar: 234
}
const obj1:{foo?:string , bar: number} = {
    bar: 789
}

const obj2: {[string]:string} = {}
obj2.value1 = 'ert'
obj2.value2 = 'errf'

//------------函数作为参数
function fooFn(callback:(string,number) => void){ //函数参数为string，number  返回值没有或为undefined
    callback('string',100)
}

fooFn(function(str,num){
    
})

//-------------
const b1: string | number ='123'

type stringOrNumber = string | number;

const gender: ?number = null

function fn(value: mixed){
    if(typeof value ==='string'){
        value.substr(0,1)
    }
    if(typeof value === 'number'){
        value * value
    }
}

//——---------------
 
const html : HTMLElement | null =  document.getElementById("app") // HTMLElement 类型
